<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="keyword" content="">

    <title>工程巡查管理-项目团队管理</title>

    <!-- Bootstrap core CSS -->
    <link href="__PUBLIC__/css/bootstrap.min.css" rel="stylesheet">
    <link href="__PUBLIC__/css/bootstrap-reset.css" rel="stylesheet">
    <!--external css-->
    <link href="__PUBLIC__/assets/font-awesome/css/font-awesome.css" rel="stylesheet" />
    <!-- Custom styles for this template -->
    <link href="__PUBLIC__/css/style.css" rel="stylesheet">
    <link href="__PUBLIC__/css/style-responsive.css" rel="stylesheet" />
    
   
    <!-- new styles-->
    <link href="__PUBLIC__/css/xxxstyle.css" rel="stylesheet" />
    
    <!--new dynamic table-->
    <link href="__PUBLIC__/assets/advanced-datatable/media/css/demo_page.css" rel="stylesheet" />
    <link href="__PUBLIC__/assets/advanced-datatable/media/css/demo_table.css" rel="stylesheet" />
    <link rel="stylesheet" href="__PUBLIC__/assets/data-tables/DT_bootstrap.css" />
    <link rel="stylesheet" href="__PUBLIC__/css/jquery.treeview.css" />
      <!-- HTML5 shim and Respond.js IE8 support of HTML5 tooltipss and media queries -->
    <!--[if lt IE 9]>
      <script src="__PUBLIC__/js/html5shiv.js"></script>
      <script src="__PUBLIC__/js/respond.min.js"></script>
    <![endif]-->
  </head>

  <body>

      <!--header start-->

      <!--sidebar end-->
      <!--main content start-->
      <section>
          <section class="wrapper site-min-height">
              <div class="row">
                <div class="SyUserListLeft">
                      <div class="panel">
                          <div class="panel-heading"><i class="glyphicon glyphicon-home"></i>项目团队</div>
                          <div class="panel-body">
                            <div id="StaffTree" class="tree tree-plus-minus tree-min-height">
                          	  <ul id="navigation">
                                <foreach name="corporate" item="v" key="kk">
                                  <li><span>{$v.cat_name}</span>
                                     <ul id="cc">
                                            <foreach name="v['user']" item="vvv" key="kkkk">
                                              <li onclick='nali("{$vvv.admin_id}")'><span>{$vvv.name}</span></li>
                                            </foreach>
                                     </ul>
                                  </li>
                                </foreach>
                              </ul>
                            </div> 
                          </div>
                      </div>
                  </div> 
                  <div class="SyUserListRight">
                      <div class="SyUserListRbox">
                          <div class="col-lg-12">
                              <section class="panel">
                                  <header class="panel-heading"><i class="icon-user"></i>团队成员</header>
                                  <div class="panel-body">
                                      <div class="adv-table" id="tableindex">
                                          <table  class="display table table-bordered table-striped" id="dynamic-table">
                                          <thead>
                                            <tr>
                                          		<!-- <td style="width: 1px;" class="text-center">
										                            <input type="checkbox" onclick="$('input[name*=\'selected\']').prop('checked', this.checked);">
										                          </td> -->
                                              <th class="hidden-phone">编号</th>
                                              <th>姓名</th>
                                              <th>手机号</th>
                                              <th>角色</th>
                                              <th>公司</th>
                                              <th>部门</th>
                                              <th>岗位</th>
                                            </tr>
                                          </thead>
                                          <tbody>
                                           		<foreach name="userList" item="vv" key="kk">
                                           		<tr aid="{$vv.admin_id}" role_id="{$vv.role_id}" uname="{$vv.name}" user_name="{$vv.user_name}" post="{$vv.post}" company="{$vv.company}" department="{$vv.department}">
                                                 <!--  <td class="text-center">
                    								                <input type="checkbox" name="selected[]" value="{$vv.admin_id}">
               									                  </td>  -->
                                                  <th class="hidden-phone">{$vv.admin_id}</th>
                                                  <th>{$vv.name}</th>
                                                  <th>{$vv.user_name}</th>
                                                  <th>{$vv.role}</th>
                                                  <th>{$vv.company}</th>
                                                  <th>{$vv.department}</th>
                                                  <th>{$vv.post}</th>
                                              </tr>
                                              </foreach>
                                          </tbody>
                                          </table>
                                      </div>
                                      <div class="adv-btn">
                                         <?php if($_SESSION['role']==1 || $_SESSION['role'] ==6):?>
                                          <button class="btn btn-submit" data-toggle="modal" href="#myModal"><i class="glyphicon glyphicon-plus"></i>添加</button>
                                          <button class="btn btn-primary" data-toggle="modal" onclick="update();"><i class="glyphicon glyphicon-edit"></i>修改</button>
                                          <button class="btn btn-danger" id="advtable-delete" onclick="del();"><i class="glyphicon glyphicon-trash" style="top:2px;"></i>删除</button>
                                          <?php endif?>
                                                     <!-- Modal 新增成员 -->
                                          <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                                              <div class="modal-dialog">
                                                  <div class="modal-content">
                                                      <div class="modal-header">
                                                          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                                          <h4 class="modal-title">新增成员</h4>
                                                      </div>
                                                          <div class="modal-body">
                                                           <div class="form-group">
                                                              <label class="col-sm-3 control-label">姓名</label>
                                                              <div class="col-sm-9">
                                                                  <input type="text" class="form-control" value="" name="name" maxlength="4" onblur="this.value=this.value.replace(/[^\u4e00-\u9fa5]/g,'')">
                                                              </div>
                                                          </div>
                                                          <div class="form-group">
                                                              <label class="col-sm-3 control-label">手机</label>
                                                              <div class="col-sm-9">
                                                                  <input type="text" class="form-control" value="" name="user_name">
                                                              </div>
                                                          </div>
                                                            <div class="form-group">
                                                              <label class="col-sm-3 control-label">密码</label>
                                                              <div class="col-sm-9">
                                                                  <input type="password" class="form-control" value="" name="password">
                                                              </div>
                                                          </div>
                                                          <div class="form-group">
                                                              <label class="col-sm-3 control-label">所属公司</label>
                                                               <div class="col-sm-9">
                                                              <select name="cid" class="form-control"  id="company">
                                 								 	<option>请选择</option>
							                               			<volist name="corporate" id="item">
							                         					<option value="{$item.cat_id}">{$item.cat_name}</option>
							                         				</volist>                  
                         									 </select>    
                         									 <span class="caret"></span>
                         									   </div>
                                                          </div>
                                                          <div class="form-group">
                                                              <label class="col-sm-3 control-label">所属行业</label>
                                                                   <div class="col-sm-9">
                                                              <select class="form-control" id="er">
                                                              		<option value="0">请选择</option>
                                 								 	<option value="1">设计</option>
                                 								 	<option value="2">咨询</option>
                                 								 	<option value="3">监理</option>
                                 								 	<option value="4">施工企业</option>
                                 								 	<option value="5">建设单位</option>
                         									  </select>   
                         									  <span class="caret"></span> 
                         									       </div>
                                                          </div>
                                                          <div class="form-group">
                                                              <label class="col-sm-3 control-label">岗位名称</label>
                                                               <div class="col-sm-9">
                                                               <input type="text" class="form-control" value="" name="post">
                                                              </div>
                                                          </div>
                                                          <div class="form-group">
                                                              <label class="col-sm-3 control-label">所属角色</label>
                                                              <div class="col-sm-9">
                                 								 <select name="role_id" class="form-control" id="role">
                                 								 		<option>请选择</option>
							                               			<volist name="role" id="item">
							                         					<option rid="{$item.role_id}">{$item.role_name}</option>
							                         				</volist>                  
                         										</select>    
                         										<span class="caret"></span>
                                                              </div>
                                                          </div>
                                                      </div>
                                                      <div class="modal-footer">
                                                          <button data-dismiss="modal" class="btn btn-default" type="button">取消</button>
                                                          <button class="btn btn-submit" type="button" onclick="add()">添加</button>
                                                      </div>
                                                  </div>
                                              </div>
                                          </div>
                                          <!-- modal -->
                                          <!-- Modal 修改成员 -->
                                          <div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel2" aria-hidden="true">
                                              <div class="modal-dialog">
                                                  <div class="modal-content">
                                                      <div class="modal-header">
                                                          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                                          <h4 class="modal-title">修改成员</h4>
                                                      </div>
                                                      <div class="modal-body">
                                                      	   <div class="form-group">
                                                              <label class="col-sm-3 control-label">姓名</label>
                                                              <div class="col-sm-9">
                                                                  <input type="text" class="form-control" value="{$info.name}" id="uname">
                                                              </div>
                                                          </div>
                                                          <div class="form-group">
                                                              <label class="col-sm-3 control-label">手机</label>
                                                              <div class="col-sm-9">
                                                                  <input type="text" class="form-control" value="{$info.user_name}" id="user_name">
                                                              </div>
                                                          </div>
                                                          <div class="form-group">
                                                              <label class="col-sm-3 control-label">密码</label>
                                                              <div class="col-sm-9">
                                                                  <input type="password" class="form-control" value="{$info.password}" placeholder="为空则不修改" id="password">
                                                              </div>
                                                          </div>
                                                           <div class="form-group">
                                                              <label class="col-sm-3 control-label">所属公司</label>
                                                               <div class="col-sm-9">
                                                              <select name="cid" class="form-control"  id="company2">
							                               			<volist name="corporate" id="item">
							                         					<option value="{$item.cat_id}" eid="{$item.cat_name}">{$item.cat_name}</option>
							                         				</volist>                  
                         									 </select>    
                         									 <span class="caret"></span>
                         									 </div>
                                                          </div>
                                                          <div class="form-group">
                                                              <label class="col-sm-3 control-label">所属行业</label>
                                                                   <div class="col-sm-9">
                                                              <select class="form-control" id="er2">
                                                              		<option value="0" vid="请选择">请选择</option>
                                 								 	<option value="1" vid="设计">设计</option>
                                 								 	<option value="2" vid="咨询">咨询</option>
                                 								 	<option value="3" vid="监理">监理</option>
                                 								 	<option value="4" vid="施工企业">施工企业</option>
                                 								 	<option value="5" vid="建设单位">建设单位</option>
                         									  </select>   
                         									  <span class="caret"></span>
                         									       </div>
                                                          </div>
                                                          <div class="form-group">
                                                             <label class="col-sm-3 control-label">岗位名称</label>
                                                               <div class="col-sm-9">
                                                               <input type="text" class="form-control" value="" name="post2" id="post2">
                                                              </div>
                                                          </div>
                                                          <div class="form-group">
                                                              <label class="col-sm-3 control-label">所属角色</label>
                                                              <div class="col-sm-9">
                                                                   <select name="role_id" class="form-control" id="rolee" onchange="chan(this);">
							                               			<volist name="role" id="item">
							                         				<option rrid="{$item.role_id}">{$item.role_name}</option>
							                         				</volist>                  
                         										</select>    
                         										<span class="caret"></span>
                                                              </div>
                                                          </div>
                                                      </div>
                                                       <div class="modal-footer">
                                                          <button data-dismiss="modal" class="btn btn-default" type="button">取消</button>
                                                          <button class="btn btn-submit" type="button" onclick="edit();">修改</button>
                                                      </div>
                                                  </div>
                                              </div>
                                          </div>
                                          <!-- modal -->
                                      </div>
                                  </div>
                              </section>
                          </div>
                      </div>
                  </div>
              </div>

          </section>
      </section>
      <!--main content end-->
    <!-- js placed at the end of the document so the pages load faster -->
    <script src="__PUBLIC__/js/jquery.js"></script>
    <script src="__PUBLIC__/js/jquery-1.8.3.min.js"></script>
    <script src="__PUBLIC__/js/bootstrap.min.js"></script>
    <script src="__PUBLIC__/js/jquery.scrollTo.min.js"></script>
    <script src="__PUBLIC__/js/jquery.nicescroll.js" type="text/javascript"></script>
    <script src="__PUBLIC__/js/jquery.customSelect.min.js" ></script>
    <!--common script for all pages-->
    <script src="__PUBLIC__/js/common-scripts.js"></script>
    <!--new script for this page only-->
  
      <!--dynamic table initialization -->
      <script src="__PUBLIC__/js/jquery-migrate-1.2.1.min.js"></script>
      <script class="include" type="text/javascript" src="__PUBLIC__/js/jquery.dcjqaccordion.2.7.js"></script>
      <script type="text/javascript" language="javascript" src="__PUBLIC__/assets/advanced-datatable/media/js/jquery.dataTables.js"></script>
      <script type="text/javascript" src="__PUBLIC__/assets/data-tables/DT_bootstrap.js"></script>
      <script src="__PUBLIC__/js/dynamic_table_init.js"></script>
      <script src="__PUBLIC__/js/respond.min.js" ></script>
      <script type="text/javascript" src="__PUBLIC__/js/layer/layer.js"></script>
      <!--  -->  
      <script src="__PUBLIC__/js/jquery.cookie.js" type="text/javascript"></script>
	    <script src="__PUBLIC__/js/jquery.treeview.js" type="text/javascript"></script>
      <script>
          //change事件
          function chan(o){
        	 // alert(1);exit;
        	 $("#role option:first").remove();
          }
          //修改用户
          function update(){
        	 var id = $("tr.selected").attr('aid');
        	 var user_name = $("tr.selected").attr('user_name');
        	 var uname = $("tr.selected").attr('uname');
        	 var post = $("tr.selected").attr('post');
        	 var company = $("tr.selected").attr('company');
        	 var department = $("tr.selected").attr('department');
        	 var role_id = $("tr.selected").attr('role_id');
        	 if(!id){
        		 layer.msg('请选择编辑的用户',{icon:2});
    	   		 return false;
        	 }else{
        		 //$("#post2 option").text(post);
        		 $("#user_name").attr('value',user_name);
        		 $("#uname").attr('value',uname);
        		 $("#post2").attr('value',post);
        		// $("#er2 option").text(department);
        		 $("#rolee option[rrid='"+role_id+"']").attr("selected",true);
        		 $("#company2 option[eid='"+company+"']").attr("selected",true);
        		 $("#er2 option[vid='"+department+"']").attr("selected",true);
        		 $('#myModal2').modal('show');
        	 }
          }
          //ajax修改
          function edit(){
        	  var id = $("tr.selected").attr('aid');
        	  var user_name = $("input[id='user_name']").val();
        	  var name = $("input[id='uname']").val();
        	  var password = $("input[id='password']").val();
        	  var department = $('#er2  option:selected').val();
        	  var post = $("input[id='post2']").val();
        	  var company = $('#company2  option:selected').val();
        	  var role_id =  $('#rolee  option:selected').attr('rrid');
        	  var reg = /(^1[3|4|5|7|8][0-9]{9}$)/;
        	  if(!id){
        		  layer.msg('ID不能为空',{icon:2});
        		  return;
        	  }
        	  if(name==''){
        		  layer.msg('姓名不能为空',{icon:2});
        		  return;
        	  }
        	  if(!reg.test(user_name)){
        		  layer.msg('手机格式不正确',{icon:2});
        		  return;
        	  }
        	  if(department=='请选择'){
        		  layer.msg('请选择部门',{icon:2});
        		  return;
        	  }
        	  if(post=='0'){
        		  layer.msg('请填写岗位',{icon:2});
        		  return;
        	  }
        		 $.ajax({
	    		 		type : 'post',
	    		 		url : '/Admin/edituser',
	    		 		data : {user_name:user_name,password:password,department:department,post:post,company:company,role_id:role_id,admin_id:id,name:name},
	    		 		dataType : 'json',
	    		 		success : function(res){
	    		 			 if(res.status==0){
								layer.alert(res.info, {icon: 2});
								return;
							 }
	    		 			 if(!res.errNo){
	    		 				 layer.msg(res.msg,{icon:1});
	    		 				 setTimeout("location.reload()",2000);
	    			          }else{
	    			        	 layer.msg(res.msg,{icon:2});
	    			          }
	    		 		}
	    		     })
        	  
          }
          //删除用户
          function del(){
        	  var id = $("tr.selected").attr('aid');
        	  if(!id){
         		 layer.msg('请选择删除的用户',{icon:2});
     	   		 return false;
         	 }
       		layer.confirm('删除后不可恢复,您确认删除吗？', {
         		  btn: ['确定','取消'] //按钮
         		}, function(){
	     		 $.ajax({
	    		 		type : 'post',
	    		 		url : '/Admin/deluser',
	    		 		data : {id:id},
	    		 		dataType : 'json',
	    		 		success : function(res){
	    		 			 if(res.status==0){
								layer.alert(res.info, {icon: 2});
								return;
							 }
	    		 			 if(!res.errNo){
	    		 				 layer.msg(res.msg,{icon:1});
	    		 				 setTimeout("location.reload()",2000);
	    			          }else{
	    			        	 layer.msg(res.msg,{icon:2});
	    			          }
	    		 		}
	    		     })
         		}, function(index){
        			layer.close(index);
        			return false;// 取消
        		}
         		);
          }
          //添加用户
          function add(){
        	  var user_name = $("input[name='user_name']").val();
        	  var name = $("input[name='name']").val();
        	  var password = $("input[name='password']").val();
        	  var company = $('#company option:selected').val();
        	  var department = $('#er option:selected').val();
        	  var post = $("input[name='post']").val();
        	  var reg = /(^1[3|4|5|7|8][0-9]{9}$)/;
        	  var role_id =  $('#role  option:selected').attr('rid');
        	  if(name==''){
        		  layer.msg('姓名不能为空',{icon:2});
        		  return;
        	  }
        	  if(user_name=='' || password==''){
        		  layer.msg('手机或密码不能为空',{icon:2});
        		  return;
        	  }
        	  if(!reg.test(user_name)){
        		  layer.msg('手机格式不正确',{icon:2});
        		  return;
        	  }
        	  if(password.length < 8){
        		  layer.msg('密码不能少于8位',{icon:2});
        		  return;
        	  }
        	  if(company=='请选择'){
        		  layer.msg('请选择公司',{icon:2});
        		  return;
        	  }
        	  if(department==0){
        		  layer.msg('请选择行业',{icon:2});
        		  return;
        	  }
        	  if(post==''){
        		  layer.msg('请选择岗位',{icon:2});
        		  return;
        	  }
        	  if(role_id==undefined){
        		  layer.msg('请选择角色',{icon:2});
        		  return;
        	  }
       		 $.ajax({
       		 		type : 'post',
       		 		url : '/Admin/adduser',
       		 		data : {user_name:user_name,password:password,department:department,post:post,company:company,role_id:role_id,name:name},
       		 		dataType : 'json',
       		 		success : function(res){
       		 	     	 if(res.status==0){
							layer.alert(res.info, {icon: 2});
							return;
						 }
       		 			 if(!res.errNo){
       		 				 layer.msg(res.msg,{icon:1});
       		 				 setTimeout("location.reload()",2000);
       			          }else{
       			        	 layer.msg(res.msg,{icon:2});
       			          }
       		 		}
       		     })
          }
          
          /**
           *点击列表选择
           */
           function nali(na){
        	   $.ajax({
  				 url: '__URL__/indexdetail',
  				 type: 'post',
  				 data: {admin_id:na},
  				 success: function(data){
  					 $("#tableindex").html('');
  					 $("#tableindex").append(data);
  				 }
  			    });
           }
      </script>
  </body>
</html>
